﻿using System;
using System.Collections.Generic;
using viNews.Classes;
using viNews.Controllers;
using visinia.SmartEngine;
using visinia.SmartEngine.Modules;

public partial class Modules_viNews_NewsnLinks_NewsnLinks : WebModule
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
            List<News> newsList = DataFilterController.GetFilteredData(ModuleId);
            if (newsList == null)
                return;
            if (newsList.Count > 0)
            {
                News news = newsList[0];
                if (news == null)
                    return;
                string url = news.Url;
                bool temp = false;
                bool.TryParse((string)Settings["HideImage"], out temp);                
                if(temp == true)
                    MIGHTHIDE.Visible = false;
                else
                {
                    IMAGE.Src = WebRoots.GetResourcesRoot + news.ImageUrl;
                    IMAGE_LINK.HRef  = url;
                }
                TITLE_LINK.InnerText = news.Title;
                TITLE_LINK.HRef = url;
                SUMMARY.Text = TrimSummary(news.Summary);

                NEWSLINKS.DataSource = newsList.GetRange(1, newsList.Count - 1);
                NEWSLINKS.DataBind();
            }
        
    }

    private string TrimSummary(string Summary)
    {
        int SummaryCharCount = 0;
        Int32.TryParse((string)Settings["SummaryCharCount"], out SummaryCharCount);
        if (SummaryCharCount > 0)
        {
            if (SummaryCharCount < Summary.Length)
            {
                return Summary.Remove(SummaryCharCount);
            }
        }
        return Summary;
    }    
}